package com.woniuxy.dr_mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.dr_mall.entity.DrFavoriteView;
import com.woniuxy.dr_mall.entity.DrOrders;
import com.woniuxy.dr_mall.entity.DrUser;
import com.woniuxy.dr_mall.entity.DrUserFavorite;
import com.woniuxy.dr_mall.provider.DrUserProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.nio.file.attribute.AclFileAttributeView;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 张哲轩
 * @since 2021-08-11
 */
public interface DrUserMapper extends BaseMapper<DrUser> {
    @Select("select * from dr_user where account = #{account}")
    DrUser getByAccount(String account);

    @Select("select * from dr_user where account=#{account} and password=#{password}")
    DrUser getByActAndPwd(@Param("account") String account,@Param("password") String password);

    @Update("update dr_user set password=#{password} where id=#{id}")
    void editPasswordById(@Param("id") Integer id,@Param("password")String password);

    //通过Userid查询用户的信息 2021-8-13 叶官鑫
    @Select("select * from dr_user where id=#{userId}")
    DrUser selectImformationById(int userId);

    //通过id修改用户传过来的数据 2021-8-14 叶官鑫
    @UpdateProvider(type =DrUserProvider.class,method = "update")
    void useIdUpdateImformation(DrUser drUser);

    //通过id,查询用户收藏的信息 2021-8-16 叶官鑫
    @Select("select * from dr_favorite_view where userid=#{userId}")
    @Results({
            @Result(property ="productId" ,column = "productid"),
            @Result(property = "price",column = "productid",one =@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrSpecPriceMapper.productIdSelectPrice")),
            @Result(property = "picture",column = "productid",one=@One( fetchType = FetchType.LAZY,select = "com.woniuxy.dr_mall.mapper.DrPictureMapper.selectProductsPicture"))
    })
    List<DrFavoriteView> useUserIdSelectImformation(int userId);

    /**
     * 获取用户的全部信息
     * @return
     */
    @Select("select *from dr_user")
    List<DrUser> getUsers();

    /**
     * 通过id修改用户状态
     * @param id
     */
    @Update("update dr_user set status='y' where id=#{id}")
    void getNormal(int id);

    /**
     * 通过id修改用户状态
     * @param id
     */
    @Update("update dr_user set status='n' where id=#{id}")
    void getUnNormal(int id);

    @Select("select * from dr_user where id = #{id}")
    DrUser getById(int id);
}
